package main

import (
	"flag"
	"fmt"
	"food-mgr/food-service/configs"
	"food-mgr/food-service/handler/service"
	"food-mgr/food-service/inits"
	__ "food-mgr/food-service/proto"
	"log"
	"net"

	"google.golang.org/grpc"
)

var (
	port = flag.Int("port", 50051, "The server port")
)

func main() {

	configs.Configs()
	configs.Develop()
	configs.Feature()
	inits.Mysql()
	inits.Redis()
	inits.Es()
	consul := inits.ServiceConsul{
		ConsulAddr:  "14.103.202.69:8500",
		ServiceName: "user_service",
		ServiceID:   "user_service_1",
		ServiceHost: "14.103.202.69",
		ServicePort: 8080,
		Tags:        []string{"v1", "api"},
	}
	inits.RegisterConsul(consul)
	flag.Parse()
	lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port))
	if err != nil {
		log.Fatalf("failed to listen: %v", err)
	}
	s := grpc.NewServer()
	__.RegisterFoodServer(s, &service.Service{})
	log.Printf("server listening at %v", lis.Addr())
	if err := s.Serve(lis); err != nil {
		log.Fatalf("failed to serve: %v", err)
	}
}
